package com.meks.crmi.app;

import java.sql.DriverManager;
import java.sql.SQLException;

import javax.inject.Inject;
import javax.inject.Singleton;
import javax.persistence.EntityManager;

import com.google.inject.persist.PersistService;

@Singleton
public class AppInitialzier {
	
	private final PersistService service;
	
	
	
	@Inject AppInitialzier(PersistService service) {
		this.service = service;
		initialize();
		// At this point JPA is started and ready.
	}
	
	public void initialize() {
		service.start();
	}
	
	public void shutdown(EntityManager em) {
//		em.createNativeQuery("checkpoint");
//		em.createNativeQuery("shutdown compact");
//		try {
//			DriverManager.getConnection("jdbc:derby:;shutdown=true");
//		} catch (SQLException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
		service.stop();
		
	}
}
